<?php
	include "template/header.php";
	include "function.php";
	
 if(isset($_SESSION['tipo_usuario'])){
 
		$id = $_SESSION['tipo_usuario'];
		$cd = $_SESSION['cd_pessoa'];
		
		if($id == '7' || $id == '6' ){	
	
	
?>
	
	<div id="doc_table" align="center">
	<br />
	<?php
		if($_GET['id'] == 1){
			//$_SESSION['teste'] = 1;
	?>
	<h2>Lista de Médicos</h2>
	<table cellspacing=0 border=0>
		<tr align="left" id="table_title">
			<th>Matricula</th><th>Nome</th><th>Especialidade</th><th>Gerir</th>
		</tr>
	<?php
		$sql = "select * from medicos";
		
		$rs = mysql_query($sql, $con);
		if($rs){
		while($reg = mysql_fetch_array($rs)) {
		$esp = $reg['especialidade'];
								
								if($esp == 1){
									$x = "  Ginecologia ";
								}		
								else if($esp == 2){
									$x = "  Pediatra ";
								}
								else{
									$x = "  Dentista ";
								}
	?>
		<tr align="left">
			<th width="100px"><?php echo $reg['crm'] ?></th>
			<th width="200px"><?php echo $reg['nome'] ?></th>
			
			
			
			
			<th width="200px"><?php echo $x ?></th>
			<th width="200px">
				<a href="edit.php?seq=<?php echo $reg['cd_pessoa'] ?>">Edit</a>
				<a href="delete.php?seq=<?php echo $reg['cd_pessoa'] ?>">Delete</a>
			</th>
		</tr>
	<?php
		}}
		else{
			echo mysql_error();
		
		}
	?>
	</table>
	<?php
		echo "<br />".
		"<a href='index.php'><button>Voltar</button></a>";
		}
	 ?>
	 
	<?php
		if($_GET['id'] == 2){
			$_SESSION['teste'] = 2;
	?>
	<h2>Lista de Funcionários</h2>
	<table cellspacing=0 border=0>
		<tr align="left" id="table_title">
			<th>Matricula</th><th>Nome</th><th>Função</th><th>Gerir</th>
		</tr>
	<?php
		$sql = "select * from funcionario";
		
		$rs = mysql_query($sql, $con);

		while($reg = mysql_fetch_array($rs)){
				$func = $reg ['funcao'];
				$x = null;
				if($func == '2'){
					$x = 'Medico';
				}
				else if ($func == '3'){
					$x = 'Repcionista';
				}
				else if ($func == '4'){
					$x = 'Farmaceutico';
				}
				else if ($func == '5'){
					$x = 'Enfermeiro';
				}
				else if ($func == '6'){
					$x = 'Admistrador';
				}
				else if ($func == '7'){
					$x = 'Gerente';
				}
				else{
					$x = 'Paciente';
				}
	?>
		<tr align="left">
			<th width="100px"><?php echo $reg['id'] ?></th>
			<th width="200px"><?php echo $reg['nome'] ?></th>
			

				

			
			<th width="200px"><?php echo $x ?></th>
			<th width="200px">
				<a href="edit.php?seq=<?php echo $reg['cd_pessoa'] ?>">Edit</a>
				<a href="delete.php?seq=<?php echo $reg['cd_pessoa'] ?>">Delete</a>
			</th>
		</tr>
	<?php
		}
	?>
	</table>
	<?php
		echo "<br />".
		"<a href='index.php'><button>Voltar</button></a>";
		}
	 ?>
	 
	<?php
		if($_GET['id'] == 3){
			//$_SESSION['teste'] = 3;
	?>
	<h2>Lista de Pacientes</h2>
	<table cellspacing=0 border=0>
		<tr align="left" id="table_title">
			<th>Matricula</th><th>Nome</th><th>Necessidade</th><th>Plano de Saúde</th><th>Gerir</th>
		</tr>
	<?php
		$sql = "select p.cd_pessoa, p.nm_pessoa, p.necessidades, p.planosaude ".
		"from pessoa as p where p.cd_pessoa = 1;";
		
		$rs = mysql_query($sql, $con);

		while($reg = mysql_fetch_array($rs)){
	?>
		<tr align="left">
			<th width="100px"><?php echo $reg['cd_pessoa'] ?></th>
			<th width="200px"><?php echo $reg['nm_pessoa'] ?></th>
			<th width="200px"><?php echo $reg['necessidades'] ?></th>
			<th width="200px"><?php echo $reg['planosaude'] ?></th>
			<th width="200px">
				<a href="edit.php?seq=<?php echo $reg['cd_pessoa'] ?>">Edit</a>
				<a href="delete.php?seq=<?php echo $reg['cd_pessoa'] ?>">Delete</a>
			</th>
		</tr>
	<?php
		}
	?>
	</table>
	<?php
		echo "<br />".
		"<a href='index.php'><button>Voltar</button></a>";		}
	?>
	 
	<?php
		if($_GET['id'] == 4){
	?>
	
	<?php
		//$sql = "select  * from consulta_marcada";
		echo "em progresso";
		
	?>
		
	
	<?php
		echo "<br />".
		"<a href='index.php'><button>Voltar</button></a>";
		}
	 ?>

	<?php
		if($_GET['id'] == 5){
	?>
	<h2>Lista de Consultas Marcadas</h2>
	<table cellspacing=0 border=0>
		<tr align="left" id="table_title">
			<th>Médico</th><th>Data</th><th>Hora</th><th>Disponivel</th>
		</tr>
	<?php
		$sql = "select p.cd_pessoa, p.nm_pessoa, h.dt_consulta, h.horario, h.visto ".
		"from pessoa as p inner join horario as h ".
		"on p.cd_pessoa = h.medico;";
		
		$rs = mysql_query($sql, $con);
		
		while($reg = mysql_fetch_array($rs)){
	?>
		<tr align="left">
			<th width="200px"><?php echo $reg['nm_pessoa'] ?></th>
			<th width="200px"><?php echo format_dt($reg['dt_consulta']) ?></th>
			<th width="200px"><?php echo $reg['horario'] ?></th>
			<th width="200px"><?php if ($reg['visto'] == 'x'){ echo 'NÃO';}else{ echo 'SIM';} ?></th>
		</tr>
	<?php
		}
	?>
	</table>
	<?php
		echo "<br />".
		"<a href='index.php'><button>Voltar</button></a>";
		}
	 ?>
	 
</div>
<br />
<!--<a href=""><button class="button_style">Inserir Novo</button></a>-->
<?php	

}}
	include "template/footer.php";
?>